var OutOrderSearchForm = function () {
  var template = /*html*/ `
    <div class="out-order-search-form clearfix" v-loading.fullscreen.lock="loading">
      <sys-common-search :search="search" request-url="putOutNew/getPutOutWarehouseOrderList" :search-field="searchField"
        label-width="100px" input-width="164px">
        <template slot="prepend">
          <el-form-item label="制单时间">
            <el-date-picker v-model="search.startTime" style="width:213px;" value-format="timestamp" :editable="false" :picker-options="startDateOption">
            </el-date-picker>
            -
            <el-date-picker v-model="search.endTime" style="width:213px;" value-format="timestamp" :editable="false" :picker-options="endDateOption">
            </el-date-picker>
          </el-form-item>
        </template>
        <template slot="append">
          <el-form-item label="供应商">
            <el-select clearable filterable style="width:164px" v-model="search.supplierId" @change="supplierChange" :disabled="technologyLoading">
              <el-option v-for="supplier in supplierList" :key="supplier.id" :value="supplier.id" :label="supplier.supplierName"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="加工工艺">
            <el-select clearable filterable style="width:164px" v-model="search.technology" :loading="technologyLoading">
              <el-option v-for="prodCycle in search.prodCycleList" :key="prodCycle.id" :value="prodCycle.technology" :label="prodCycle.technology"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="是否结算">
            <el-select clearable v-model="search.isBalance" class="form-input" style="width:164px;">
              <el-option v-for="balance in balanceList" :key="'balance_'+balance.value" :value="balance.value" :label="balance.label">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="单价">
            <el-input-number is-decimal-zero v-model="search.startPrice" placeholder="单价最小值" :controls="false" :min="0" :max="search.endPrice"
              :precision="2" style="width:110px"></el-input-number>
            <span>-</span>
            <el-input-number is-decimal-zero v-model="search.endPrice" placeholder="单价最大值" :controls="false" :precision="2"
              :min="search.startPrice?search.startPrice:0" style="width:110px"></el-input-number>
          </el-form-item>
        </template>
      </sys-common-search>
    </div>
  `;

  return {
    mixins:[datePickerOptionsMixin('startTime','endTime')],
    props: {
      search: {
        type: Object,
        required: true
      }
    },
    data: function () {
      return {
        supplierList: [],
        technologyLoading: false,
        loading: false,
        searchField: ['orderId', 'companyOrderId', 'factoryId', 'customerId', 'customerOrderId', 'machining'],
        balanceList: i18n.getDropDown('financeMgr.balance', ['0', '1'])
      };
    },
    created: function () {
      this.loading = true;
      var self = this;
      this.setSupplierList().then(function () {
        self.loading = false;
      }).catch(function () {
        self.loading = false;
      });
    },
    methods: {
      setSupplierList: function () {
        var self = this;
        return SysUtil.getSupplierDropDown().then(function (supplierList) {
          self.supplierList = supplierList;
          return supplierList;
        }).catch(function () {
          return [];
        });
      },
      supplierChange: function () {
        var search = this.search;
        var supplierId = search.supplierId;
        if (supplierId === '') {
          search.prodCycleList = [];
          search.technology = '';
          return;
        }

        this.technologyLoading = true;
        var self = this;
        ajaxRequest('putOutNew/getPutoutFlowCycle', {
          supplierId: supplierId,
          status: 1
        }).then(function (res) {
          self.technologyLoading = false;
          var prodCycleList = res.returnData;
          search.prodCycleList = prodCycleList;
          search.technology = '';
        }).catch(function () {
          self.technologyLoading = false;
          search.prodCycleList = [];
          search.technology = '';
        });
      }
    },
    components: {
      SysCommonSearch: SysCommonSearch
    },
    template: template
  };
}();